package com.example.wly.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main2ButtonActivity extends AppCompatActivity {
    static int count=0;
    private TextView tvinfo;//快捷键ctrl+alt+F

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2_button);
         //1-找到button
        //快捷键 Ctrl+alt+v声明局部变量

        Button btnStart1=(Button)findViewById(R.id.btn_start) ;
        tvinfo = (TextView) findViewById(R.id.tv_info);
        MyListener listener=new MyListener();
        btnStart1.setOnClickListener(listener);

    }
    //写一个方法，执行按钮点击之后处理代码
    //名字  和onclick属性值一一致，btnstart
    //参数是一个发生点击事件的控件
    public  void  btnStart(View v){
        //输出一个信息，按钮被点击
        //日志log
        //参数1-标签名，方便查找
        //参数2标签的内容
        Log.i("Main11","按钮被点击");
    }
    class MyListener implements View.OnClickListener{
        public void onClick(View v){
            count++;
            StringBuffer bs=new StringBuffer("hello");
            for(int i=0;i<count-1;i++)
            {
                bs.append(" hello");

            }
            tvinfo.setText(bs);
        }
    }
}
